(function() {
  app.controller('payflowCtrl', function($scope, tradeApi, returnData) {
    $scope.condition = [{
      head: '收/支',
      options: [
          { txt: '全部', value: '' },
          { txt: '收入', value: '0' },
          { txt: '支出', value: '1' },
      ],
      default: { txt: '全部', value: '' },
    },
    {
      head: '日期',
      options: [
          { txt: '全部', value: '20170901' },
          { txt: '7天之内', value: 7 },
          { txt: '15天之内', value: 15 },
      ],
      default: { txt: '7天之内', value: 7 },
    }
    ];

    $scope.init = function() {
      $scope.actived = 0;
      $scope.client_pay_flow();
    };

    $scope.tab_click = function(i) {
      $scope.actived = i;
      if (i === 0) {
        $scope.condition[0].head = '收/支';
        $scope.condition[0]['options'][1] = { txt: '收入', value: '0' };
        $scope.condition[0]['options'][2] = { txt: '支出', value: '1' };
      } else if (i === 1) {
        $scope.condition[0].head = '创建/平仓';
        $scope.condition[0]['options'][1] = { txt: '创建', value: '0' };
        $scope.condition[0]['options'][2] = { txt: '平仓', value: '1' };
      }

      $scope.condition[0].default = { txt: '全部', value: '' };
      $scope.condition[1].default = { txt: '全部', value: 90 };
      $scope.client_pay_flow();

    };

    $scope.client_pay_flow = function() {
      var funcId;
      funcId = $scope.actived === 0 ? '300023' : '300025';

      var data = returnData.dateSet($scope.condition[1].default.value);
      data.fund_direction = $scope.condition[0].default.value;
      tradeApi.query({
        funcId: funcId,
        data: data
      }).then(function(result) {
        angular.forEach(result, function(item) {
          if (item.business_name === '签约' || item.business_name === '扣息' || item.business_name === '追加保证金' || item.business_name === '提取盈利' || item.business_name === '结算') {
            item.display_name = 'VIP业务账号：' + item.serial_no;
          }else if(item.business_type==='3'||item.business_type==='4'||item.business_type==='5'){
            item.display_name = '协议编号：' + item.serial_no;
          }else{
            item.display_name = '订单编号：' + item.serial_no;
          }
        });
        $scope.pay_flows = result;
      });
    };
  });

})();
